#include <stdio.h>
#include <stdlib.h>

struct chain
{
	int value;
	struct chain *next;		//典型的链表节点，指针域和结构体一样
};

struct chain *create()
{
	struct chain *head, *tail, *p;
	int x;
	head = tail = NULL;
	printf("input data: ");
	while(scanf("%d", &x) == 1)
	{
		p = (struct chain *)malloc(sizeof(struct chain));
		p->value = x;
		p->next = NULL;
		if(head == NULL)
			head = tail = p;
		else
		{
			tail = tail->next;
			tail->next = p;
		}
	}
	return head;
}

int main()
{
	struct chain *p, *q;
	q = create();
	while(q)
	{
		printf("%d\n", q->value);
		p = q->next;
		free(q);
		q = p;
	}
}
